package com.niuke;

import java.util.Scanner;

public class NiuKe3 {

    public static void main(String[] args) {
        Scanner sc1 = new Scanner(System.in);
        String line1 = sc1.nextLine();
        String[] a = line1.split(" ");
        String[][] data = new String[Integer.parseInt(a[0])][Integer.parseInt(a[1])];
        for (int i = 0; i < Integer.parseInt(a[0]); i++) {
            data[i] = sc1.nextLine().split(" ");
        }
        String area = sc1.nextLine();
        System.out.println(getAns(data, area));
    }

    public static int getAns(String[][] data, String area) {
        int row = data.length;
        int col = data[0].length;
        int[][] dataNum = new int[row][col];

        for (int i = 0; i < row; i++) {
            for (int j = 0; j < col; j++) {
                String str = data[i][j];
                if (str.startsWith("=")) {
                    if (str.contains("+")) {
                        int index = str.indexOf("+");
                        String sub1 = str.substring(1, index);
                        String sub2 = str.substring(1 + index);
                        int[] a = getIndex(sub1);
                        int[] b = getIndex(sub2);
                        int a1 = a[0] != -1 ? Integer.parseInt(data[a[0]][a[1]]) : a[1];
                        int b1 = b[0] != -1 ? Integer.parseInt(data[b[0]][b[1]]) : b[1];
                        dataNum[i][j] = a1 + b1;
                    } else if (str.contains("-")) {
                        int index = str.indexOf("-");
                        String sub1 = str.substring(1, index);
                        String sub2 = str.substring(1 + index);
                        int[] a = getIndex(sub1);
                        int[] b = getIndex(sub2);
                        int a1 = a[0] != -1 ? Integer.parseInt(data[a[0]][a[1]]) : a[1];
                        int b1 = b[0] != -1 ? Integer.parseInt(data[b[0]][b[1]]) : b[1];
                        dataNum[i][j] = a1 - b1;
                    } else {
                        String sub1 = str.substring(1);
                        int[] a = getIndex(sub1);
                        dataNum[i][j] = a[0] != -1 ? Integer.parseInt(data[a[0]][a[1]]) : a[1];
                    }
                } else {
                    int num = Integer.parseInt(str);
                    dataNum[i][j] = num;
                }
            }
        }
        
        String[] areaArr = area.split(":");
        int[] start = getIndex(areaArr[0]);
        int[] end = getIndex(areaArr[1]);
        int res = 0;
        for (int i = start[0]; i <= end[0]; i++) {
            for (int j = start[1]; j <= end[1]; j++) {
                res += dataNum[i][j];
            }
        }
        return res;
    }

    public static int[] getIndex(String bianhao) {
        int[] res = new int[2];
        if (bianhao.charAt(0) >= '0' && bianhao.charAt(0) <= '9') {
            res[0] = -1;
            res[1] = Integer.parseInt(bianhao);
        } else {
            res[0] = Integer.parseInt(bianhao.substring(1)) - 1;
            res[1] = bianhao.charAt(0) - 'A';
        }
        return res;
    }

}
